import os,base64
import datetime

def getDay(day): 
    if day == '今天':
        return datetime.date.today() 
    elif day == '昨天':
        today=datetime.date.today() 
        oneday=datetime.timedelta(days=1) 
        yesterday=today-oneday  
        return yesterday
    elif day == '前天':
        today=datetime.date.today() 
        twoday=datetime.timedelta(days=2) 
        return today-twoday 
    elif day == '大前天':
        today=datetime.date.today() 
        threeday=datetime.timedelta(days=3) 
        return today-threeday  
    else:
        raise RuntimeError("Bad Day %s" % (day))
    

def getYesterday(): 
    return getDay('昨天')

# 将图片转码为base64
# file_name文件名称
# 默认图片根目录为项目目录下的img目录
def img_to_base64(file_name):
    with open(file_name, "rb") as f:
        # b64encode是编码，b64decode是解码
        base64_data = base64.b64encode(f.read())
        image = base64_data.decode("utf-8")
    return image

# 从环境变量中获取secretId和secretKey
def secret():
    secret_id = os.environ.get("secretId")
    secret_key = os.environ.get("secretKey")
    return secret_id, secret_key
    
if __name__ == "__main__":
    secret_id,secret_key = secret()
    print(secret_id)
    print(secret_key)
    # dataUrl = img_to_base64("static/images/demo-card-1.jpg")
    # with open("upload/pybase64.txt","w") as file:
    #     file.write(dataUrl)
    # with open("upload/base64.txt") as file:
    #     lines = file.readlines()
    #     print(lines[0][22])
    